<?php

// us phone numbers
class Quad_Data_Phone extends Quad_Data_Abstract {
	
	public $number;
	public $matcher = '/^1?\D*([2-9]\d{2})\D*([2-9]\d{2})\D*(\d{4})($|\D.*$)/';
	
	public function __construct($no = '') {
		$this->raw = $no;
		$this->number = trim($no);
	}
	
	public static function create($no) {
		return new self($no);
	}
	
	public function isValid() {
		return (preg_match($this->matcher, $this->number, $m) && $m[2] != '555');
	}
	
	public function format() {
		if (preg_match($this->matcher, $this->number, $m)) {
			return "({$m[1]}) {$m[2]}-{$m[3]}{$m[4]}";
		}
		return $this->number;
	}
	
}